/**
 * @file FOC.h
 * @author Aiano_czm
 * @brief
 */

#ifndef FOC_DRIVER_FOC_H
#define FOC_DRIVER_FOC_H

#include "stdint.h"

#define FOC_CONTROL_MODE_NUM 10
typedef enum{
    OPEN_LOOP_SPEED_CONTROL=0,
    OPEN_LOOP_POSITION_CONTROL,
    TORQUE_CONTROL,
    SPEED_CONTROL,
    POSITION_CONTROL,
    SPRING,
    SPRING_WITH_DAMP,
    DAMP,
    KNOB,
    ZERO_RESISTANCE
} FOC_CONTROL_MODE;
typedef enum
{
    TORQUE,
    VELOCITY,
    ANGLE,
    VELOCITY_OPEN_LOOP,
    ANGLE_OPEN_LOOP
}ControlMode_t;
enum Error_t
{
    NO_ERROR = 0,
    FAILED_TO_NOTICE_MOVEMENT,
    POLE_PAIR_MISMATCH
};
enum Direction
{
    CW = 1,
    CCW = -1,
    UNKNOWN = 0
};
extern float target_velocity;
extern float target_angle;

void magneticTest(uint16_t tick);

void FOC_init();
void alignSensor(void);
float get_electrical_angle();
void velocityOpenLoop(float target_velocity);
void angleOpenLoop(float target_angle);
void setPhaseVoltage(float Uq, float Ud, float angle);
void move(float new_target);
void loopFoc(void);
#endif //FOC_DRIVER_FOC_H
